home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRNSAVE.PAK / TSCRNSAV.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  230 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1995 by Borland International, All Rights Reserved
  4. //
  5. //   Windows desktop screensaver classes.
  6. //----------------------------------------------------------------------------
  7. #include <owl/pch.h>
  8. #include <owl/dialog.h>
  9. #include "tscrnsav.h"
  10.  
  11. DEFINE_RESPONSE_TABLE1(TScrnSavWindow, TFrameWindow)
  12.   EV_WM_MOUSEMOVE,
  13.   EV_WM_LBUTTONDOWN,
  14.   EV_WM_RBUTTONDOWN,
  15.   EV_WM_MBUTTONDOWN,
  16.   EV_WM_ACTIVATE,
  17.   EV_WM_ACTIVATEAPP,
  18.   EV_WM_KEYDOWN,
  19.   EV_WM_SYSKEYDOWN,
  20.   EV_WM_SYSCOMMAND,
  21. END_RESPONSE_TABLE;
  22.  
  23. //
  24. //
  25. //
  26. TScrnSavWindow::TScrnSavWindow(TWindow* parent, const char* title, TModule* module)
  27. :
  28.   TFrameWindow(parent, title, 0, false, module)
  29. {
  30.   ShowCursor(false);
  31.   Attr.Style = WS_POPUP;
  32. }
  33.  
  34. //
  35. //
  36. //
  37. TScrnSavWindow::~TScrnSavWindow()
  38. {
  39.   ShowCursor(true);
  40. }
  41.  
  42. //
  43. //
  44. //
  45. void
  46. TScrnSavWindow::GetWindowClass(WNDCLASS& wndClass)
  47. {
  48.   TWindow::GetWindowClass(wndClass);
  49.   wndClass.hIcon = 0;
  50.   wndClass.style |= CS_SAVEBITS;
  51.   wndClass.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
  52. }
  53.  
  54. //
  55. //
  56. //
  57. void
  58. TScrnSavWindow::SetupWindow()
  59. {
  60.   TFrameWindow::SetupWindow();
  61.   GetCursorPos(PrevPt);
  62.   TRect r;
  63.   ::GetWindowRect(GetDesktopWindow(), &r);
  64.   MoveWindow(r, true);
  65. }
  66.  
  67. //
  68. //
  69. //
  70. void
  71. TScrnSavWindow::EvMouseMove(uint, TPoint& point)
  72. {
  73.   if (point != PrevPt)
  74.     PostMessage(WM_CLOSE);
  75. }
  76.  
  77. //
  78. //
  79. //
  80. void
  81. TScrnSavWindow::EvLButtonDown(uint, TPoint&)
  82. {
  83.   PostMessage(WM_CLOSE);
  84. }
  85.  
  86. //
  87. //
  88. //
  89. void
  90. TScrnSavWindow::EvRButtonDown(uint, TPoint&)
  91. {
  92.   PostMessage(WM_CLOSE);
  93. }
  94.  
  95. //
  96. //
  97. //
  98. void
  99. TScrnSavWindow::EvMButtonDown(uint, TPoint&)
  100. {
  101.   PostMessage(WM_CLOSE);
  102. }
  103.  
  104. //
  105. //
  106. //
  107. void
  108. TScrnSavWindow::EvActivate(uint active, bool, HWND)
  109. {
  110.   if (!active)
  111.     PostMessage(WM_CLOSE);
  112. }
  113.  
  114. //
  115. //
  116. //
  117. #if defined(BI_PLAT_WIN32)
  118. void TScrnSavWindow::EvActivateApp(bool active, HANDLE)
  119. #else
  120. void TScrnSavWindow::EvActivateApp(bool active, HTASK)
  121. #endif
  122. {
  123.   if (!active)
  124.     PostMessage(WM_CLOSE);
  125. }
  126.  
  127. //
  128. //
  129. //
  130. void
  131. TScrnSavWindow::EvKeyDown(uint, uint, uint)
  132. {
  133.   PostMessage(WM_CLOSE);
  134. }
  135.  
  136. //
  137. //
  138. //
  139. void
  140. TScrnSavWindow::EvSysKeyDown(uint, uint, uint)
  141. {
  142.   PostMessage(WM_CLOSE);
  143. }
  144.  
  145. //
  146. //
  147. //
  148. void
  149. TScrnSavWindow::EvSysCommand(uint cmdType, TPoint&)
  150. {
  151.   if ((cmdType & 0xFFF0) != SC_SCREENSAVE)
  152.     DefaultProcessing();
  153. }
  154.  
  155. //
  156. //
  157. //
  158. int
  159. TScrnSavApp::Run()
  160. {
  161.   if (strcmp(lpCmdLine, "/c") == 0 || strcmp(lpCmdLine, "-c") == 0) {
  162.     Configuring = true;
  163.     InitConfigDialog();
  164.     
  165.     // Get the desktop control panel applet's window handle and make a
  166.     // TWindow out of it.
  167.     //
  168.     HWND deskAppletHWnd = ::FindWindow(WC_DIALOG, "Desktop");
  169.     TWindow* deskAppletWnd = 0;
  170.     if (deskAppletHWnd)
  171.       deskAppletWnd = new TWindow(deskAppletHWnd);
  172.  
  173.     // Set our config dialog to have the applet window as its parent if
  174.     // available
  175.     //
  176.     if (deskAppletWnd)
  177.       ConfigureDialog->SetParent(deskAppletWnd);
  178.     ConfigureDialog->Execute();
  179.     delete ConfigureDialog;
  180.  
  181.     // When our alias is destructed, it remove its thunk, & restores old proc
  182.     //
  183.     delete deskAppletWnd;
  184.     return 0;
  185.   }
  186.   else {
  187.     Configuring = false;
  188.     return TApplication::Run();
  189.   }
  190. }
  191.  
  192. //
  193. //
  194. //
  195. void
  196. TScrnSavApp::InitMainWindow()
  197. {
  198.   Configuring = false;
  199.   InitScrnSavWindow();
  200.   if (ScrnSavWnd)
  201.     MainWindow = ScrnSavWnd;
  202.   LastTime = GetCurrentTime();
  203. }
  204.  
  205. //
  206. //
  207. //
  208. void
  209. TScrnSavApp::InitScrnSavWindow()
  210. {
  211.   ScrnSavWnd = new TScrnSavWindow(0, 0, 0);
  212. }
  213.  
  214. //
  215. //
  216. //
  217. bool
  218. TScrnSavApp::IdleAction(long)
  219. {
  220.   if (!Configuring) {
  221.     uint32 diffTime = GetCurrentTime() - LastTime;
  222.     if (Speed == 2 || Speed == 1 && diffTime > 10 || diffTime > 50) {
  223.       ScrnSavWnd->AnimateScreen();
  224.       LastTime = GetCurrentTime();
  225.     }
  226.     return true;
  227.   }
  228.   return false;
  229. }
  230.